package com.neusoft.neuiotms.dcom.repository.change.impl;

import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

import com.neusoft.bizcore.web.jpa.repository.AbstractRepository;
import com.neusoft.bizcore.web.support.Searchable;
import com.neusoft.neuiotms.dcom.model.change.ChangeCiProperty;
import com.neusoft.neuiotms.dcom.model.change.QChangeCiProperty;
import com.neusoft.neuiotms.dcom.repository.change.CustomizedChangeCiPropertyRepository;
import com.querydsl.core.BooleanBuilder;
import com.querydsl.jpa.impl.JPAQuery;

public class CustomizedChangeCiPropertyRepositoryImpl extends AbstractRepository
        implements CustomizedChangeCiPropertyRepository {

    @Override
    public List<ChangeCiProperty> index(final Searchable searchable) {
        final QChangeCiProperty qChangeCiProperty = QChangeCiProperty.changeCiProperty;
        final BooleanBuilder where = this.buildWhere(searchable);
        final JPAQuery<ChangeCiProperty> query = this.query().selectFrom(qChangeCiProperty);
        query.where(where);
        return query.fetch();
    }

    @Override
    public Page<ChangeCiProperty> search(final Pageable pageable, final Searchable searchable) {
        final QChangeCiProperty qChangeCiProperty = QChangeCiProperty.changeCiProperty;
        final BooleanBuilder where = this.buildWhere(searchable);
        final JPAQuery<ChangeCiProperty> query = this.query().selectFrom(qChangeCiProperty);
        query.where(where);
        return super.search(query, pageable);
    }

    @Override
    protected Class<?> getModelClass() {
        return ChangeCiProperty.class;
    }

    private BooleanBuilder buildWhere(final Searchable searchable) {
        final BooleanBuilder where = new BooleanBuilder();
        return where;
    }

}
